package com.example.blog.demos.web.service;

import com.example.blog.demos.web.mapper.BlogInfoMapper;
import com.example.blog.demos.web.mapper.UserInfoMapper;
import com.example.blog.demos.web.model.BlogInfo;
import com.example.blog.demos.web.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 实现接收到的请求
 * @author Q
 * @create 2025-06-21-10:31
 */
@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;
    public UserInfo selectUserInfoByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    public UserInfo selectUserInfoById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }
    public UserInfo selectAuthorInfoByBlogId(Integer blogId) {
        //1. 根据博客ID, 获取作者ID
        BlogInfo blogInfo = blogInfoMapper.selectById(blogId);
        //2. 根据作者ID, 获取作者信息
        if (blogInfo == null || blogInfo.getUserId()==null){
            return null;
        }
        UserInfo userInfo = userInfoMapper.selectById(blogInfo.getUserId());
        return userInfo;
    }
}
